<template>
  <div id="app" class="sinux_app" v-loading="isLoading">
    <router-view v-if="!isLoading"/>
  </div>
</template>

<script>

export default {
  name: 'App',
  data() {
    return {
      isLoading: true
    }
  },
  mounted() {
    Promise.all([this._info(), this._tree(), this.getDict(), this.getButtonPermissions()]).then(() => {
      this.isLoading = false
    }).catch(() => {
      this.$message.error({
        message: '系统初始化失败',
        duration: 1500,
        center: true,
        onClose: () => {
          this.isLoading = false
          if (!process.env.OFFLINE) {
            window.location = process.env.SERVER_URL
          }
        }
      })
    })
  },
  updated() {
  },
  methods: {
    /**
     * @desc 获取按钮权限
     */
    getButtonPermissions () {
      this.$store.dispatch('saveData', {
        method: 'get',
        url: 'a/rest/sys/menu/permissions',
        noCommit: true
      }).then((res) => {
        this.$store.commit('SetButtonPermissions', res.data)
      })
    },
    // 获取用户信息
    _info() {
      return this.$store.dispatch('saveData', {
        method: 'get',
        url: 'a/api/sysinfo',
        // url: 'a/webmessage/webMessage/getusername',
        noCommit: true
      }).then((res) => {
        this.$store.commit('SetUserInfo', res.data)
      })
    },
    // 获取用户菜单
    _tree() {
      return this.$store.dispatch('saveData', {
        method: 'get',
        url: 'a/rest/sys/menu/tree',
        noCommit: true
      }).then(res => {
        let children = res.data.children || [{name: 'mes', children: []}]
        let mes = children.find(item => item.name === 'mes')
        this.$store.commit('SetTree', mes.children)
        // let arr = mes.children
        // let rootDir = arr.find(item => item.href === to.meta.rootDir) || {children: []}
        // let subMenu = rootDir.children.find(item => item.href === to.meta.subMenu) || {children: []}
        // let menuItem = subMenu.children.find(item => item.href === to.meta.menuItem)
      })
    },
    // 获取字典
    getDict() {
      return this.$store.dispatch('saveData', {
        method: 'get',
        url: `a/dictionary/dict/all`,
        commit: 'SetDict',
        module: 'dict'
      })
    }
  }
}
</script>

<style lang="less">
  @commonFont:'Microsoft YaHei', 'Avenir', Helvetica, Arial, sans-serif;
  body, p {
    margin: 0;
  }

  html, body{
    height: 100%;
  }
  body {
    overflow: hidden;
  }

  .el-message {
    top: 98px;
    padding: 10px 15px;
  }

  #app {
    font-family: @commonFont;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100%;
    .el-submenu .el-menu {
      background-color: #1d2637 !important;
    }
    .el-scrollbar__wrap {
      overflow: auto;
    }
    .mes_btn span{
      font-family: @commonFont;
    }
    .el-input__inner, .el-textarea__inner{
      font-family: @commonFont;
    }
  }
  .el-select-dropdown__item span{
    font-family: @commonFont;
  }
  .el-tooltip__popper{
    max-width: 700px;
    word-break: break-all;
    p{
      line-height: 24px;
    }
  }
  .btn_tooltip.el-tooltip__popper{
    max-width: 300px;
    word-break: break-all;
  }

  .sinux_app {
    .el-button, .el-input__inner, .el-textarea__inner {
      border-radius: 2px;
    }
    .el-tooltip__popper.is-dark {
      max-width: 400px;
      word-break: break-all;
      line-height: 1.5;
    }
    .el-select-dropdown {
      max-width: calc(30% - 90px) !important;
    }
    input::-webkit-outer-spin-button,
    input::-webkit-inner-spin-button {
      -webkit-appearance: none;
    }
    .el-loading-spinner .el-loading-text{
      color: #000;
    }
  }
</style>
